<?php
    require '../../../feed/config/config.php';
	session_start();
	$ip=getip();
	if(empty($_SESSION['Master'])){
	    echo "<script>location='../../login.php';</script>";
	}
	$total=mysqli_num_rows(mysqli_query($con,"select * from member where type='0' order by id asc"));
    $page=isset($_GET['page'])?intval($_GET['page']):1;  
    $info_num=15; 
    $pagenum=ceil($total/$info_num); 
    $offset=($page-1)*$info_num; 
    $info=mysqli_query($con,"select * from member where type='0' order by id asc limit $offset,$info_num"); 
    if(!$info) {
        printf("Error: %s\n", mysqli_error($con));
        exit();
    }
    if($_GET['user']!=""){
        $userRs=mysqli_fetch_array(mysqli_query($con,"select * from member where user='".$_GET['user']."'"));
        if($userRs['type']=="1"){
            echo "<script>alert('无法管理该账号');location='./index.php';</script>";
        }else{
            if($_GET['ops']=="no"){
                mysqli_query($con,"update member set state='0' where user='".$_GET['user']."'");
                echo "<script>alert('操作成功！');location='./index.php';</script>";
            }elseif($_GET['ops']=="yes"){
                mysqli_query($con,"update member set state='1' where user='".$_GET['user']."'");
                echo "<script>alert('操作成功！');location='./index.php';</script>";
            }
        }
    }
?>
<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title><?php echo $SysRs['name'];?> - 用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body">
      <table class="layui-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>账号</th>
            <th>邮箱</th>
            <th>状态</th>
            <th>操作</th>
        </thead>
        <tbody>
			<?php 
				echo "快捷操作：<a href='./index.php'>》刷新《</a>";
				$count=0;
				while($rs=mysqli_fetch_array($info)){ 
				
						$count=$count+1;?>
				<tr>
					<td><?php echo $count; ?></td>
					<td><?php echo $rs['user']; ?></td>
					<td><?php echo $rs['email']; ?></td>
					<td><?php 
					    if($rs['state']=="1"){
					        echo "正常";
					    }else{
					        echo "冻结";
					    }
					?></td>
					<td>
					    <?php 
					    if($rs['state']=="1"){
					        echo "<a href='?ops=no&user=".$rs['user']."'><button class='layui-btn layui-btn-normal layui-btn-mini'>冻结</button></a>";
					    }else{
					        echo "<a href='?ops=yes&user=".$rs['user']."'><button class='layui-btn layui-btn-normal layui-btn-mini'>恢复</button></a>";
					    }
					    ?>
					    
					</td>
				</tr>
			<?php	
				}
				if($count==0){
					echo "<br />暂无更多管理员！";
				}
			?> 
        </tbody>
      </table>
        <br />
        <?php
        	if( $page > 1 ){
        		echo "<a href='?page=".($page-1)."'>前一页</a>&nbsp";
        	}else{
        		echo "前一页&nbsp&nbsp";
        	}
        	for($i=1;$i<=$pagenum;$i++){
        		$show=($i!=$page)?"<a href='?page=".$i."'>".$i."</a>":"$i";
        		Echo $show." ";
        	}
        	if( $page<$pagenum){
        		echo "<a href='?page=".($page+1)."'>后一页</a>";
        	}else{
        		echo "后一页";
        	}
    	?>
    </div>
  </body>

</html>